﻿using System.Xml;
using System.Xml.Schema;
using MbUnit.Framework;

namespace MockingBird.Xml.XIG.Tests
{
    using MockingBird.Xml.XIG;


    [TestFixture]
    public class XmlSampleGeneratorTests
    {
        IXmlInstanceGenerator generator = new SimpleXmlInstanceGenerator();

        /// <summary>
        /// Tests that the Simple Instance Generator will generate a valid instance for 
        /// a given Xml Schema.
        /// </summary>
        [Test]
        public void ShouldGenerateValidSampleForGivenSchemaSet()
        {
            string xsdLocation = @"..\..\TestData\POv1.xsd";
            XmlSchemaSet schemaSet = new XmlSchemaSet();
            schemaSet.Add("http://www.mockingbird.org", new XmlTextReader(xsdLocation));
            XmlQualifiedName qName = new XmlQualifiedName("PurchaseOrder");
            XmlDocument resultDocument = generator.GenerateInstance(schemaSet, qName);
            Assert.IsNotNull(resultDocument);
            Assert.IsTrue(resultDocument.SelectNodes("//*[local-name()='ShipTo']").Count == 2);

        }
        //TODO: More tests to check whether generatorSettings is used correctly etc
    }
}
